[docs] Add CodeToggle widget; use it for install snippets#8101
Open
dokson wants to merge 1 commit into
Open
Conversation
Add CodeToggle to @blueprintjs/docs-theme: a generic tabbed code-snippet
widget that takes any number of { id, label, code } tabs and optionally
persists the user's selection in localStorage. Sits alongside CodeExample
in the published docs theme, so other consumers of @blueprintjs/docs-theme
can reuse it for their own snippet toggles.
In docs-app, register a thin InstallSnippet wrapper that supplies the
npm/yarn/pnpm install commands for @blueprintjs/core and use it on the
Blueprint and Getting Started pages via the @reactdocs Documentalist tag.
Adding another package manager (e.g. bun) is one entry in TABS in
installSnippet.tsx. Adding a different snippet toggle elsewhere is a new
thin wrapper that calls CodeToggle with its own tabs.
Fixes palantir#7684.
Generate changelog in
|
Author
|
@mm-wang — implements the toggle from #7684 as a reusable |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes #7684.
Adds a tabbed code-snippet toggle to the docs and uses it for the install commands on the Blueprint and Getting Started pages, so a reader can pick their package manager (
npm/yarn/pnpm) instead of the docs hard-coding one.Architecture
The widget is split in two:
@blueprintjs/docs-theme→<CodeToggle>— generic, reusable. Takestabs: { id, label, code }[], anidfor the underlying<Tabs>, and an optionalstorageKeyfor cross-page persistence inlocalStorage. Uses Blueprint<Tabs>,<Pre>,<Code>. Sits next to the existingCodeExamplewidget so any consumer of the docs theme can reuse it.docs-app→<InstallSnippet>— thin wrapper that supplies the npm/yarn/pnpm install commands for@blueprintjs/core react react-dom, registered as a@reactDocs InstallSnippetDocumentalist tag.Why the split: Documentalist's
@reactDocstag does not accept arguments, so each specific use case needs its own thin wrapper component registered intags/reactDocs.ts. The genericCodeTogglelives indocs-themewhere it's reusable.Extensibility
TABSarray ininstallSnippet.tsx. Tab order is the array order.<CodeToggle tabs={...} id="..." />, re-exported viatags/reactDocs.ts, then@reactDocs MyNewWidgetin the relevant MDX page.Persistence
InstallSnippetpassesstorageKey="bp-docs-pm-preference", so the reader's PM choice is remembered across pages and across visits. Default ispnpm(the docs current default after #7685). The state hydrates fromlocalStorageafter mount to avoid first-render mismatches and stays SSR-safe.Test plan
eslintclean on changed filesprettierappliedpnpm --filter @blueprintjs/docs-theme run compile:esmcleandocs-data:compileissue with Node 25; the repo's.nvmrcpins 24.14.1)No new tests: neither
docs-themenordocs-apphas a test setup today, and adding the infrastructure for a single widget felt like scope creep for this issue. Happy to follow up in a separate PR if maintainers want test coverage fordocs-themewidgets.